package chapter4.inject_value_spel;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.support.GenericXmlApplicationContext;
import org.springframework.stereotype.Service;

@Service("injectSimple")
public class InjectSimple {
	@Value("#{injectSimpleConfig.name}")
	private String name;
	@Value("#{injectSimpleConfig.age + 1}")
	private int age;
	@Value("#{injectSimpleConfig.height}")
	private float height;
	@Value("#{injectSimpleConfig.programmer}")
	private boolean programmer;
	@Value("#{injectSimpleConfig.ageSecond}")
	private Long ageSeconds;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public float getHeight() {
		return height;
	}

	public void setHeight(float height) {
		this.height = height;
	}

	public boolean isProgrammer() {
		return programmer;
	}

	public void setProgrammer(boolean programmer) {
		this.programmer = programmer;
	}

	public Long getAgeSeconds() {
		return ageSeconds;
	}

	public void setAgeSeconds(Long ageSeconds) {
		this.ageSeconds = ageSeconds;
	}

	@Override
	public String toString() {
		return "Name : " + name + "\n" + "Age : " + age + "\n" + "Height : "
				+ height + "\n" + "Programmer : " + programmer + "\n"
				+ "ageSecond : " + ageSeconds;
	}

	public static void main(String[] args) {
		// Run beam xml
		GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
		ctx.load("classpath:chapter4/inject_value_spel/application-context-xml.xml");
		ctx.refresh();
		InjectSimple simple = (InjectSimple) ctx.getBean("injectSimple");
		System.out.println(simple);

		// Run bean with annotation
		GenericXmlApplicationContext ctx2 = new GenericXmlApplicationContext();
		ctx2.load("classpath:chapter4/inject_value_spel/app-context-annotation.xml");
		ctx2.refresh();
		InjectSimple simple1 = (InjectSimple) ctx2.getBean("injectSimple");
		System.out.println(simple1);
	}
}
